$(function () {
    $('table').bootstrapTable({
        striped: true,
    });
});

function tableView(table) {
    Base.ajax({
        url: '/manage/db/view',
        data: {
            "table": table
        },
        loadingCommit: true,
        success: function (data) {
            if (data.code) {
                var arr = [];
                for (var i = 0; i < data.data.length; i++) {
                    var item = data.data[i];
                    arr.push('<tr>');
                    arr.push('<td>' + item.columnName + '</td>');
                    arr.push('<td>' + item.columnTypeName + '</td>');
                    arr.push('<td>' + item.catalogName + '</td>');
                    arr.push('<td>' + item.precision + '</td>');
                    arr.push('</tr>');
                }
                $("#tableInfo").html(arr.join(""));
                $(".modal-title").html(table + "表结构信息");
                $('#dialogTableInfo').modal('toggle');
            } else {
                tiperror("查询失败！");
            }
        }
    });
}
function tableBackupDialog(table) {
    BootstrapDialog.show({
        title: '备份提示',
        message: '请再次确认是否备份表【' + table + '】',
        type: BootstrapDialog.TYPE_DANGER,
        buttons: [{
            label: '确定',
            cssClass: 'btn-danger',
            action: function (dialog) {
                tableBackup(table);
                dialog.close();
            }
        }, {
            label: '取消',
            action: function (dialog) {
                dialog.close();
            }
        }]
    });
}

function tableBackup(table) {
    Base.ajax({
        url: '/manage/db/backup',
        data: {
            "table": table
        },
        loadingCommit: true,
        success: function (data) {
            if (data.code) {
                tipsuccess("备份成功！");
                Base.reload();
            } else {
                tiperror("备份失败！");
            }
        }
    });
}